package com.miyake.client.trash;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.miyake.client.DoctorsUserService;
import com.miyake.client.DoctorsUserServiceAsync;
import com.miyake.client.profile.AbstractUserList;
import com.miyake.client.profile.AllUserList;
import com.miyake.client.tools.ImageList;
import com.miyake.client.tools.ImageListElement;
import com.miyake.client.tools.ImageList.CommunityListHandler;

public class UserListDialog extends DialogBox {
	protected DoctorsUserServiceAsync service = DoctorsUserService.Util.getInstance();

	public UserListDialog() {
		setHTML("Find Friends");
		VerticalPanel verticalPanel = new VerticalPanel();
		setWidget(verticalPanel);
		verticalPanel.setSize("100%", "100%");
		
		AbstractUserList list = new AllUserList();
		
		verticalPanel.add(list);
		verticalPanel.add(new Button("Close", new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				hide(true);
			}
		}));
		
		list.addCommunityListHandler(new CommunityListHandler() {

			@Override
			public void onSelect(ImageListElement community) {
				addFriend(community.getKey());
			}

			@Override
			public void onFind() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onCreate(String name) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onDelete(String name) {
				// TODO Auto-generated method stub
				
			}
			
		});
	}

	protected void addFriend(String key) {
		service.addFriend(key, new AsyncCallback<Void>() {

			@Override
			public void onFailure(Throwable caught) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onSuccess(Void result) {
				hide(false);
			}
			
		});
	}


}
